package com.aimuceliang.aimuceliang.api;


import com.aimuceliang.aimuceliang.bean.HttpResult;
import com.aimuceliang.aimuceliang.utils.StringUtil;

import org.greenrobot.eventbus.EventBus;

import rx.functions.Func1;


/**
 * hepeng Created on 2016/10/8.
 * 类描述：用来统一处理Http的status,并将HttpResult的data部分剥离出来返回给subscriber
 * @param <T> data部分的数据模型
 */

public class HttpResultFunc<T> implements Func1<HttpResult<T>, T> {

    @Override
    public T call(HttpResult<T> httpResult) {
        if (!httpResult.code.equals("0")) {
            if (StringUtil.checkStr(httpResult.message)) {
                throw new ApiException(httpResult.message);
            }
        }
        return httpResult.data;
    }
}